require('scss/base.scss');

import Vue from 'vue'
import App from './App'
import router from './routes'
import filter from './filter'

//安装Vuex
import store from 'vuex/store'

//js
import dayjs from 'dayjs'
import popup from 'lib/popup/popup'
import config from 'js/config'
require('js/server');
require('js/util');
require('js/format');

//lib
require('lib/qrcode/qrcode.min');
require('js/jquery.qrcode.min');
//window
window['popup'] = popup;
window['dayjs'] = dayjs;
window['config'] = config;
window['router'] = router;

//mixin
Vue.mixin({
  methods: {
    routerGo(name, query) {
      var query = query || {};
      router.push({ name: name, query: query })
    },
    goBack(){
      router.go(-1)
    }
  }
})

// 使用filter
for (var k in filter) {
  Vue.filter(k, filter[k]);
};
router.beforeEach((to, from, next) => {
  if (!['reload', 'checkstatus'].includes(to.name)) {
  // if (!['reload', 'checkstatus', 'readrecord','program'].includes(to.name)) {
    // if (!['reload','scancode','scancode2','scancode3'].includes(to.name)){
    if (['scancode', 'scancode2', 'scancode3', 'scancode4'].includes(to.name)){
      if (to.query.online === '1'){
        server.getUserInfo(false, to);
      }
    }else{
      server.getUserInfo(false, to);
    }
  }
  $('body')[0].style.backgroundColor = '#fff';
  $(window).unbind('scroll')
  document.title = to.meta.name
  window.scrollTo(0, 0)
  next()
})

//vue-router&vuex实例
const vue = new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
window['Vue'] = vue;


